﻿using D.UtilCore;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using CozeDto.ProjectInstanceDtos;
using CozeDomain.IServices;
using D.UtilFreesqlOrm;
using CozeDto.ProjectDtos;

namespace CozeWapApi
{
    /// <summary>
    /// 站点所属项目模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    public class ProjectInstanceController : BaseApiController
    {
        private readonly IProjectInstanceService _projectInstanceService;
        public ProjectInstanceController(IProjectInstanceService projectInstanceService)
        {
            _projectInstanceService = projectInstanceService;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqAddProjectInstance"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        [UnitOfWork]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddProjectInstance reqAddProjectInstance)
        {
            reqAddProjectInstance.CreateUser = Account;
            return await _projectInstanceService.AddProjectInstanceAsync(reqAddProjectInstance);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="reqQueryProjectInstanceList"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepProjectInfo>>> List([FromBody] ReqQueryProjectInstanceList reqQueryProjectInstanceList)
        {
            return await _projectInstanceService.QueryProjectListAsync(reqQueryProjectInstanceList, LoginId);
        }

        /// <summary>
        /// 获取单个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepProjectInfo>> Get(string id)
        {
            return await _projectInstanceService.GetProjectAsync(id, LoginId);
        }

        /// <summary>
        /// 获取个人新增的助手
        /// </summary>
        /// <param name="reqQueryProjectInstanceList"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepProjectInfo>>> MyList([FromBody] ReqQueryProjectInstanceList reqQueryProjectInstanceList)
        {
            reqQueryProjectInstanceList.CreateUser = Account;
            return await _projectInstanceService.QueryProjectListAsync(reqQueryProjectInstanceList, LoginId);
        }
    }
}
